<?php
/*
	首页
*/
//cfc('core')->checklogin();
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('header','common/header-cms');
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['indexpai']=array();
	$setting = $this->plugin_setting('setting');
	if(!$setting['issearch']){
		$return['indexpai'][]=array('name'=>'search');
	}
	if(!$setting['ishdps']){
		$return['indexpai'][]=array('name'=>'hdps');
	}
	if(!$setting['isbankuai1']){
		$return['indexpai'][]=array('name'=>'bankuai1');
	}
	if(!$setting['isbankuai2']){
		$return['indexpai'][]=array('name'=>'bankuai2');
	}
	if(!$setting['iscube']){
		$return['indexpai'][]=array('name'=>'cube');
	}
	if(!$setting['isshare']){
		$return['indexpai'][]=array('name'=>'share');
	}
	$return['indexpai'][]=array('name'=>'coupon');
	$return['indexpai'][]=array('name'=>'goods');
	$p_group=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','parentid'=>'0'),'','paixu asc');
	//子分类
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$params['saletype likes']=array('1');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	if($p_group){
		$i=0;
		foreach($p_group as &$item){
			$item['c_group']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','isrecommand'=>'1','parentid'=>$item['id']),'','paixu asc');
			$item['goodslist']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('1'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$item['goodsnew']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('2'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$item['style']=style($item['id']);
			$i=$i+1;
			$item['i']=$i;
			if($item['c_group']){
				foreach($item['c_group'] as &$row){
					$params['ccate']=$row['id'];
					$row['goods']=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','paixu desc');
				}
			}
		}
	}
	$params=array(
		'table'=>'jy_weishop_goods',
		'fields'=>array('id','title','image','marketprice','price','total'),
		'orderby'=>'paixu desc',
		'limit'=>'5',
	);
	//
	$goodslist=$setting['goodsids'];
	$params['params']=array('saletype likes'=>array('1'),'uniacid'=>$_SESSION['uniacid'],'pcate'=>$setting['group_id']);
	$recommand_list=array();
	$new_list=array();
	$hot_list=array();
	if($goodslist){
		foreach($goodslist as &$item){
				$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),$fields);
				$item=array_merge($item,$goodsinfo);
				$item['unit']=$item['unit']?'/'.$item['unit']:'/件';
				$item['pcatetitle']=pdo_getcolumn('jy_weishop_goods_group',array('id'=>$item['pcate']),'title');
				$item['pcatetitle']=$item['pcatetitle']?$item['pcatetitle']:'无';
				$item['ccatetitle']=pdo_getcolumn('jy_weishop_goods_group',array('id'=>$item['ccate']),'title');
				$item['ccatetitle']=$item['ccatetitle']?$item['ccatetitle']:'无';
				$item['url']=custom_url('jy_weishop/goods.detail//id='.$item['id'],true);
				if(stripos($item['saletype'],'1')){
					$recommand_list[]=$item;
				}
				if(stripos($item['saletype'],'2')){
					$new_list[]=$item;
				}
				if(stripos($item['saletype'],'3')){
					$hot_list[]=$item;
				}
		}
	}
	
	//$time_list=$this->model('activity/limit')->goods_list(5);
	//促销
	
	//$discount_list=$this->model('activity/sales')->goods_list(5);
	//公告列表
	$notice_list = pdo_fetchall('SELECT * FROM ' . tablename('jy_weishop_notice') . ' WHERE uniacid=:uniacid AND status=1  ORDER BY id DESC limit 4', array(':uniacid' => $_SESSION['uniacid']));
	if($notice_list){
		foreach($notice_list as &$notice){
			$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
		}
	}
	//获取用户信息
	$return['indexrecommands']=$recommand_list;
	$return['extradata']=array();
	//$return['user']=model('core/member')->basic($_SESSION['uid']);
	$return['login']=$_SESSION['uid']?1:2;
	$return['recommand_list']=$recommand_list;
	$return['new_list']=$new_list;
	$return['hot_list']=$hot_list;
	$return['notice_list']=$notice_list;
	$return['goodslist']=$goodslist;
	$return['p_group']=$p_group;
	set_html('title',$setting['title']?'首页-'.$setting['title']:'首页-清仓');
	$return['sharedata']=array(
		'title'=>$setting['share_title']?$setting['share_title']:'首页-清仓',
		'desc'=>$setting['share_desc']?$setting['share_desc']:'清仓，一个属于自己的个人商城！',
		'link'=>custom_url('jy_weishop/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
	);
	exi($return);
}
function style($id)
{
	switch ($id%7) {	
		case 0: return "style-brown";
		case 1: return 'style-red';
		case 2: return "style-pink";
		case 3: return "style-orange";
		case 4: return "style-green";
		case 5: return "style-blue";
		case 6: return "style-purple";
		case 7: return "style-brown";
		default: }
}
	
?>